package com.yunshang.shoppingmall.shopping.AddressController;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yunshang.shoppingmall.common.MessageConstants;
import com.yunshang.shoppingmall.common.Response;
import com.yunshang.shoppingmall.common.layuiJson;
import com.yunshang.shoppingmall.entity.Address;
import com.yunshang.shoppingmall.entity.OrderDetailsProduct;
import com.yunshang.shoppingmall.entity.UserNo;
import com.yunshang.shoppingmall.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@RequestMapping("/wap")
@Controller
public class AddressAPIController {
    @Autowired
    AddressService addressService;
    //确认订单获取默认地址
    @RequestMapping("/getAddress")
    @ResponseBody
    public Response getAddress(HttpServletRequest request)
    {
        HttpSession session = request.getSession();
        UserNo userNo1 = (UserNo)session.getAttribute("userNo");
        int memberUserId=0;
        if(userNo1!=null)
        {
            memberUserId=userNo1.getId();
        }
        //System.out.println(memberUserId+"--------");
        Address address=addressService.selectDefault(1,memberUserId);
        if(address!=null)
        {
            return new Response(MessageConstants.MSG_SUCCESS,address,"获取成功!");
        }
        else
        {
            return new Response(MessageConstants.MSG_OPERATE_FAILED,null,"获取失败!");
        }
    }
}
